﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="users.aspx.vb" Inherits="admin_users" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <title>SmartTaxi управление - список пользователей

    </title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="row">

        <h3 style="border-bottom: 1px solid #c6c6c6">Список пользователей</h3>

        <div class="row">

            <div class="col-sm-12">

                <asp:FormView ID="FormView1" Width="100%" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="taxi_id" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Horizontal">
                    <EditItemTemplate>

                        <table style="width: 100%;">

                            <tr>
                                <td style="width: 300px; vertical-align: top" valing="top">

                                    <img style="max-height: 250px; max-width: 250px;" src="/images/<%# Eval("taxi_photo")%>" id="photoprev" />

                                    <script>

                                        if ($("#photoprev").attr("src") == "/images/") {
                                            $("#photoprev").attr("src", "http://www.mbk-center.co.th/taxi/images/taxi_logo.png");
                                        }

                                    </script>

                                    <br />
                                    <span class="lbl">Онлайн:
                                    </span>
                                    <asp:CheckBox ID="taxi_isonlineCheckBox" runat="server" Checked='<%# Bind("taxi_isonline")%>' />
                                    <br />

                                    <span class="lbl">Имя:
                                    </span>
                                    <asp:TextBox ID="taxt_firstnameTextBox" runat="server" Text='<%# Bind("taxt_firstname") %>' />
                                    <br />
                                    <span class="lbl">Фамилияs:
                                    </span>
                                    <asp:TextBox ID="taxi_lastnameTextBox" runat="server" Text='<%# Bind("taxi_lastname") %>' />
                                    <br />


                                </td>
                                <td valign="top">


                                    <span class="lbl">Номер авто:
                                    </span>
                                    <asp:TextBox ID="taxi_carnumberTextBox" runat="server" Text='<%# Bind("taxi_carnumber") %>' />
                                    <br />
                                    <span class="lbl">Марка авто:
                                    </span>
                                    <asp:TextBox ID="taxi_markaTextBox" runat="server" Text='<%# Bind("taxi_marka") %>' />
                                    <br />
                                    <span class="lbl">Модель авто:
                                    </span>
                                    <asp:TextBox ID="taxi_modelTextBox" runat="server" Text='<%# Bind("taxi_model") %>' />
                                    <br />
                                    <span class="lbl">Цвет авто:
                                    </span>
                                    <asp:TextBox ID="taxi_colorTextBox" runat="server" Text='<%# Bind("taxi_color") %>' />
                                    <br />
                                    <span class="lbl">Пароль:
                                    </span>
                                    <asp:TextBox ID="taxi_passwordTextBox" runat="server" Text='<%# Bind("taxi_password") %>' />
                                    <br />
                                    <span class="lbl">Телефон:
                                    </span>
                                    <asp:TextBox ID="taxi_phoneTextBox" runat="server" Text='<%# Bind("taxi_phone") %>' />
                                    <br />
                                    <span class="lbl">Подтвержден телефон?
                                    </span>
                                    <asp:CheckBox ID="taxi_phoneconfirmCheckBox" runat="server" Checked='<%# Bind("taxi_phoneconfirm") %>' />
                                    <br />
                                    <span class="lbl">Дата регистрации:
                                    </span>
                                    <asp:TextBox ID="taxi_createdTextBox" runat="server" Text='<%# Bind("taxi_created") %>' />
                                    <br />
                                    <span class="lbl">Разрешен:
                                    </span>
                                    <asp:CheckBox ID="taxi_isaceptedCheckBox" runat="server" Checked='<%# Bind("taxi_isacepted") %>' />
                                    <br />
                                    <span class="lbl">Город:
                                    </span>
                                    <asp:TextBox ID="citiesTextBox" runat="server" Text='<%# Bind("city_name")%>' />
                                    <br />
                                    <span class="lbl">Рейтинг:
                                    </span>
                                    <asp:Label ID="ratingTextBox" runat="server" Text='<%# Bind("rating_value")%>' />
                                    <br />

                                </td>

                                <td rowspan="2" style="width: 500px;" valign="top">

                                    <table style="width: 500px;">
                                        <thead>

                                            <tr>
                                                <td>Телефон</td>
                                                <td>Дата заказа
                                                </td>
                                                <td>Откуда
                                                </td>

                                                <td>Куда</td>

                                                <td>Цена
                                                </td>
                                                <td>Статус
                                                </td>
                                            </tr>
                                        </thead>

                                        <tbody>


                                            <%
                                                GetContext()
                                                Dim ords = GetContext.torders.Where(CType(Function(x) x.taxi_id = GridView1.SelectedDataKey.Value And x.torder_status > 4, Func(Of torders, Boolean))).OrderByDescending(Function(x) x.torder_created).Take(20)
                                    
                                                For Each o As torders In ords
                                        
                                            %>

                                            <tr>
                                                <td><%= o.orders.order_user_phone%></td>
                                                <td><%= o.orders.order_create%></td>

                                                <td><%= o.orders.order_from_address%></td>

                                                <td><%= o.orders.order_to_address%></td>
                                                <td><%= o.torder_price%></td>
                                                <td><% Select Case o.torder_status
                                                   
                                                            Case 0
                                                                Response.Write("в ожидании")
                                                            Case 1
                                                                Response.Write("отправлено ценовое предложение")
                                                            Case 2
                                                                Response.Write("водитель не ответил")
                                                            Case 3
                                                                Response.Write("клиент отказал")
                                                            Case 4
                                                                Response.Write("водитель отказал")
                                                            Case 5
                                                                Response.Write("клиент не ответил")
                                                            Case 6
                                                                Response.Write("клиент принял")
                                                            Case 7
                                                                Response.Write("заказ выполнен")
                                                            Case 8
                                                                Response.Write("таксист не приехал")
                                                        End Select%></td>

                                            </tr>

                                            <%
                                        
                                            Next
                                    
                                            %>
                                        </tbody>
                                    </table>

                                </td>


                            </tr>

                            <tr>


                                <td colspan="2" style="height: 200px;">

                                    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA3sLB3h-BO7EBw7D8MoOy1PLlARb5dZus&sensor=false">
                                    </script>


                                    <div id="map_canvas" style="width: 100%; height: 100%"></div>

                                    <script type="text/javascript">
                                        function initialize() {

                                            var mapOptions = {
                                                center: new google.maps.LatLng(<%# Eval("taxi_location")%>),
                  zoom: 8,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
              };
              var map = new google.maps.Map(document.getElementById("map_canvas"),
                  mapOptions);


              var marker = new google.maps.Marker({
                  position: new google.maps.LatLng(<%# Eval("taxi_location")%>),
                                             title: "Водитель здесь"
                                         });

              // To add the marker to the map, call setMap();
                                             marker.setMap(map);

                                         }
                                         initialize();
                                    </script>

                                </td>



                            </tr>

                        </table>





                        <%-- <span class="lbl">
                    ID таксиста:
                    </span>
                    <asp:Label ID="taxi_idLabel" runat="server" Text='<%# Eval("taxi_id") %>' />
                    <br />
                        --%>

                        <%--<span class="lbl">
                    Координаты таксиста:
                        </span>
                    <asp:Label ID="taxi_locationLabel" runat="server" Text='<%# Bind("taxi_location") %>' />
                    <br />
                        --%>
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" Width="150px" />
                    <InsertItemTemplate>
                        taxi_id:
                    <asp:TextBox ID="taxi_idTextBox" runat="server" Text='<%# Bind("taxi_id") %>' />
                        <br />
                        taxi_location:
                    <asp:TextBox ID="taxi_locationTextBox" runat="server" Text='<%# Bind("taxi_location") %>' />
                        <br />
                        taxi_isonline:
                    <asp:CheckBox ID="taxi_isonlineCheckBox" runat="server" Checked='<%# Bind("taxi_isonline") %>' />
                        <br />
                        taxt_firstname:
                    <asp:TextBox ID="taxt_firstnameTextBox" runat="server" Text='<%# Bind("taxt_firstname") %>' />
                        <br />
                        taxi_lastname:
                    <asp:TextBox ID="taxi_lastnameTextBox" runat="server" Text='<%# Bind("taxi_lastname") %>' />
                        <br />
                        taxi_photo:
                    <asp:TextBox ID="taxi_photoTextBox" runat="server" Text='<%# Bind("taxi_photo") %>' />
                        <br />
                        taxi_carnumber:
                    <asp:TextBox ID="taxi_carnumberTextBox" runat="server" Text='<%# Bind("taxi_carnumber") %>' />
                        <br />
                        taxi_marka:
                    <asp:TextBox ID="taxi_markaTextBox" runat="server" Text='<%# Bind("taxi_marka") %>' />
                        <br />
                        taxi_model:
                    <asp:TextBox ID="taxi_modelTextBox" runat="server" Text='<%# Bind("taxi_model") %>' />
                        <br />
                        taxi_color:
                    <asp:TextBox ID="taxi_colorTextBox" runat="server" Text='<%# Bind("taxi_color") %>' />
                        <br />
                        taxi_password:
                    <asp:TextBox ID="taxi_passwordTextBox" runat="server" Text='<%# Bind("taxi_password") %>' />
                        <br />
                        taxi_phone:
                    <asp:TextBox ID="taxi_phoneTextBox" runat="server" Text='<%# Bind("taxi_phone") %>' />
                        <br />
                        taxi_phoneconfirm:
                    <asp:CheckBox ID="taxi_phoneconfirmCheckBox" runat="server" Checked='<%# Bind("taxi_phoneconfirm") %>' />
                        <br />
                        taxi_created:
                    <asp:TextBox ID="taxi_createdTextBox" runat="server" Text='<%# Bind("taxi_created") %>' />
                        <br />
                        taxi_isacepted:
                    <asp:CheckBox ID="taxi_isaceptedCheckBox" runat="server" Checked='<%# Bind("taxi_isacepted") %>' />
                        <br />
                        city_id:
                    <asp:TextBox ID="city_idTextBox" runat="server" Text='<%# Bind("city_id") %>' />
                        <br />
                        last_code:
                    <asp:TextBox ID="last_codeTextBox" runat="server" Text='<%# Bind("last_code") %>' />
                        <br />
                        last_reser:
                    <asp:TextBox ID="last_reserTextBox" runat="server" Text='<%# Bind("last_reser") %>' />
                        <br />
                        taxi_lastaction:
                    <asp:TextBox ID="taxi_lastactionTextBox" runat="server" Text='<%# Bind("taxi_lastaction") %>' />
                        <br />
                        cities:
                    <asp:TextBox ID="citiesTextBox" runat="server" Text='<%# Bind("cities") %>' />
                        <br />
                        rating:
                    <asp:TextBox ID="ratingTextBox" runat="server" Text='<%# Bind("rating") %>' />
                        <br />
                        torders:
                    <asp:TextBox ID="tordersTextBox" runat="server" Text='<%# Bind("torders") %>' />
                        <br />
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </InsertItemTemplate>
                    <ItemTemplate>

                        <table style="width: 100%;">

                            <tr>
                                <td style="width: 300px; vertical-align: top" valing="top">

                                    <img style="max-height: 250px; max-width: 250px;" src="/images/<%# Eval("taxi_photo")%>" id="photoprev" />

                                    <script>

                                        if ($("#photoprev").attr("src") == "/images/") {
                                            $("#photoprev").attr("src", "http://www.mbk-center.co.th/taxi/images/taxi_logo.png");
                                        }

                                    </script>

                                    <br />
                                    <span class="lbl">Онлайн:
                                    </span>
                                    <asp:CheckBox ID="taxi_isonlineCheckBox" runat="server" Checked='<%# Bind("taxi_isonline")%>' Enabled="false" />
                                    <br />

                                    <span class="lbl">Имя:
                                    </span>
                                    <asp:Label ID="taxt_firstnameLabel" runat="server" Text='<%# Bind("taxt_firstname") %>' />
                                    <br />
                                    <span class="lbl">Фамилия:
                                    </span>
                                    <asp:Label ID="taxi_lastnameLabel" runat="server" Text='<%# Bind("taxi_lastname") %>' />
                                    <br />


                                </td>
                                <td valign="top">


                                    <span class="lbl">Номер авто:
                                    </span>
                                    <asp:Label ID="taxi_carnumberLabel" runat="server" Text='<%# Bind("taxi_carnumber") %>' />
                                    <br />
                                    <span class="lbl">Марка авто:
                                    </span>
                                    <asp:Label ID="taxi_markaLabel" runat="server" Text='<%# Bind("taxi_marka") %>' />
                                    <br />
                                    <span class="lbl">Модель авто:
                                    </span>
                                    <asp:Label ID="taxi_modelLabel" runat="server" Text='<%# Bind("taxi_model") %>' />
                                    <br />
                                    <span class="lbl">Цвет авто:
                                    </span>
                                    <asp:Label ID="taxi_colorLabel" runat="server" Text='<%# Bind("taxi_color") %>' />
                                    <br />
                                    <span class="lbl">Пароль:
                                    </span>
                                    <asp:Label ID="taxi_passwordLabel" runat="server" Text='<%# Bind("taxi_password") %>' />
                                    <br />
                                    <span class="lbl">Телефон:
                                    </span>
                                    <asp:Label ID="taxi_phoneLabel" runat="server" Text='<%# Bind("taxi_phone") %>' />
                                    <br />
                                    <span class="lbl">Подтвержден телефон?
                                    </span>
                                    <asp:CheckBox ID="taxi_phoneconfirmCheckBox" runat="server" Checked='<%# Bind("taxi_phoneconfirm") %>' Enabled="false" />
                                    <br />
                                    <span class="lbl">Дата регистрации:
                                    </span>
                                    <asp:Label ID="taxi_createdLabel" runat="server" Text='<%# Bind("taxi_created") %>' />
                                    <br />
                                    <span class="lbl">Разрешен:
                                    </span>
                                    <asp:CheckBox ID="taxi_isaceptedCheckBox" runat="server" Checked='<%# Bind("taxi_isacepted") %>' Enabled="false" />
                                    <br />
                                    <span class="lbl">Город:
                                    </span>
                                    <asp:Label ID="citiesLabel" runat="server" Text='<%# Bind("city_name")%>' />
                                    <br />
                                    <span class="lbl">Рейтинг:
                                    </span>
                                    <asp:Label ID="ratingLabel" runat="server" Text='<%# Bind("rating_value")%>' />
                                    <br />

                                </td>

                                <td rowspan="2" style="width: 500px;" valign="top">

                                    <table style="width: 500px;">
                                        <thead>

                                            <tr>
                                                <td>Телефон</td>
                                                <td>Дата заказа
                                                </td>
                                                <td>Откуда
                                                </td>

                                                <td>Куда</td>

                                                <td>Цена
                                                </td>
                                                <td>Статус
                                                </td>
                                            </tr>
                                        </thead>

                                        <tbody>


                                            <%
                                                GetContext()
                                                Dim ords = GetContext.torders.Where(CType(Function(x) x.taxi_id = GridView1.SelectedDataKey.Value And x.torder_status > 4, Func(Of torders, Boolean))).OrderByDescending(Function(x) x.torder_created).Take(20)
                                    
                                                For Each o As torders In ords
                                        
                                            %>

                                            <tr>
                                                <td><%= o.orders.order_user_phone%></td>
                                                <td><%= o.orders.order_create%></td>

                                                <td><%= o.orders.order_from_address%></td>

                                                <td><%= o.orders.order_to_address%></td>
                                                <td><%= o.torder_price%></td>
                                                <td><% Select Case o.torder_status
                                                   
                                                            Case 0
                                                                Response.Write("в ожидании")
                                                            Case 1
                                                                Response.Write("отправлено ценовое предложение")
                                                            Case 2
                                                                Response.Write("водитель не ответил")
                                                            Case 3
                                                                Response.Write("клиент отказал")
                                                            Case 4
                                                                Response.Write("водитель отказал")
                                                            Case 5
                                                                Response.Write("клиент не ответил")
                                                            Case 6
                                                                Response.Write("клиент принял")
                                                            Case 7
                                                                Response.Write("заказ выполнен")
                                                            Case 8
                                                                Response.Write("таксист не приехал")
                                                        End Select%></td>

                                            </tr>

                                            <%
                                        
                                            Next
                                    
                                    
                                            %>
                                        </tbody>
                                    </table>

                                </td>


                            </tr>

                            <tr>


                                <td colspan="2" style="height: 200px;">

                                    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA3sLB3h-BO7EBw7D8MoOy1PLlARb5dZus&sensor=false">
                                    </script>


                                    <div id="map_canvas" style="width: 100%; height: 100%"></div>

                                    <script type="text/javascript">
                                        function initialize() {

                                            var mapOptions = {
                                                center: new google.maps.LatLng(<%# Eval("taxi_location")%>),
                                             zoom: 8,
                                             mapTypeId: google.maps.MapTypeId.ROADMAP
                                         };
                                         var map = new google.maps.Map(document.getElementById("map_canvas"),
                                             mapOptions);


                                         var marker = new google.maps.Marker({
                                             position: new google.maps.LatLng(<%# Eval("taxi_location")%>),
                title: "Водитель здесь"
            });

           // To add the marker to the map, call setMap();
                marker.setMap(map);

            }
            initialize();
                                    </script>

                                </td>



                            </tr>

                        </table>





                        <%-- <span class="lbl">
                    ID таксиста:
                    </span>
                    <asp:Label ID="taxi_idLabel" runat="server" Text='<%# Eval("taxi_id") %>' />
                    <br />
                        --%>

                        <%--<span class="lbl">
                    Координаты таксиста:
                        </span>
                    <asp:Label ID="taxi_locationLabel" runat="server" Text='<%# Bind("taxi_location") %>' />
                    <br />
                        --%>



                        <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Редактировать" />
                        &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Удалить" />
                        &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="Добавить" />
                    </ItemTemplate>
                    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                    <RowStyle CssClass="min_form" />
                </asp:FormView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:1gb_smarttaxiConnectionString %>" SelectCommand="SELECT [taxi_id], [taxi_location], [taxi_isonline], [taxt_firstname], [taxi_lastname], [taxi_photo], [taxi_carnumber], [taxi_marka], (SELECT city_name FROM cities WHERE cities.city_id =  taxist.city_id) as city_name, [taxi_isacepted], [taxi_created], [taxi_phoneconfirm], [taxi_phone], [taxi_password], [taxi_color], [taxi_model], (SELECT AVG([rating_rate]) FROM [rating] WHERE [rating].[taxi_id] = [taxist].[taxi_id]) as rating_value FROM [taxist] WHERE ([taxi_id] = @taxi_id)" UpdateCommand="UPDATE taxist SET taxt_firstname =@taxt_firstname , taxi_lastname =@taxi_lastname , taxi_carnumber =@taxi_carnumber , taxi_marka =@taxi_marka , taxi_model =@taxi_model , taxi_color =@taxi_color , taxi_password =@taxi_password, taxi_phoneconfirm =@taxi_phoneconfirm , taxi_phone =@taxi_phone  , taxi_created =@taxi_created , taxi_isacepted =@taxi_isacepted WHERE taxi_id=@taxi_id" DeleteCommand="DELETE FROM [taxist] WHERE [taxi_id] = @id">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:ControlParameter ControlID="GridView1" DefaultValue="NULL" Name="taxi_id" PropertyName="SelectedValue" Type="Object" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:ControlParameter ControlID="GridView1" Name="taxi_id" PropertyName="SelectedDataKey" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=TaxiEntities" DefaultContainerName="TaxiEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="taxist">
                </asp:EntityDataSource>
                <br />
                <asp:GridView ID="GridView1" runat="server" AllowCustomPaging="True" AutoGenerateColumns="False" DataKeyNames="taxi_id" DataSourceID="EntityDataSource1" Width="100%">
                    <Columns>
                        <asp:BoundField DataField="taxt_firstname" HeaderText="Имя" ReadOnly="True" SortExpression="taxt_firstname" />
                        <asp:BoundField DataField="taxi_lastname" HeaderText="Фамилия" ReadOnly="True" SortExpression="taxi_lastname" />
                        <asp:BoundField DataField="taxi_lastaction" HeaderText="Последняя активность" ReadOnly="True" SortExpression="taxi_lastaction" />
                        <asp:BoundField DataField="taxi_phone" HeaderText="Телефон" ReadOnly="True" SortExpression="taxi_phone" />
                        <asp:BoundField DataField="taxi_carnumber" HeaderText="Номер авто" ReadOnly="True" SortExpression="taxi_carnumber" />
                        <asp:BoundField DataField="taxi_marka" HeaderText="Марка" ReadOnly="True" SortExpression="taxi_marka" />
                        <asp:BoundField DataField="taxi_model" HeaderText="Модель" ReadOnly="True" SortExpression="taxi_model" />
                        <asp:BoundField DataField="taxi_color" HeaderText="Цвет" ReadOnly="True" SortExpression="taxi_color" />

                        <asp:TemplateField>
                            <HeaderTemplate>
                                <b>Баланс</b>
                            </HeaderTemplate>
                            <ItemTemplate>

                                <%# CInt(( CType(Eval("taxi_balance"), List(Of transfers)).Sum(Function(i) i.transfer_amount)))%>
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:CommandField ShowSelectButton="True" />
                    </Columns>
                </asp:GridView>
                <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=TaxiEntities" DefaultContainerName="TaxiEntities" EnableFlattening="False" EntitySetName="taxist" Select="it.[taxt_firstname], it.[taxi_lastname], it.[taxi_lastaction], it.[taxi_phone], it.[taxi_marka], it.[taxi_model], it.[taxi_color], it.[taxi_carnumber], it.[taxi_id], it.[transfers] as taxi_balance" EntityTypeFilter="">
                </asp:EntityDataSource>

            </div>

        </div>

    </div>

</asp:Content>

